package com.uplooking.controller;

import java.sql.Timestamp;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.uplooking.service.BusService;
import com.uplooking.service.CustService;
import com.uplooking.service.RentService;

@Controller
public class RentController {

	@Autowired
	private RentService rentService;

	@Autowired
	private BusService busService;

	@Autowired
	private CustService custService;

	@RequestMapping(value = "/rent/info", method = RequestMethod.GET)
	public String methodRent1() {
		return "service/rent/info";
	}

	@RequestMapping(value = "/rent/index", method = RequestMethod.GET)
	public String methodRent2() {
		return "service/rent/index";
	}

	@ResponseBody
	@RequiresPermissions("rent!list")
	@RequestMapping(value = "/rent/list", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodRent3(String rtid, int index, int size, int step) throws Exception {
		return JSONObject.toJSONString(rentService.getRentList(rtid, index, size, step));
	}

	@ResponseBody
	@RequiresPermissions("rent!add")
	@RequestMapping(value = "/rent/add", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	public String methodRent4(int rtextprice, Timestamp rtbegin, Timestamp rtreturn, String rtctid, String rtdesc,
			String no) throws Exception {
		return JSONObject.toJSONString(
				rentService.addRent(rtextprice, rtbegin, rtreturn, rtctid, rtdesc, busService.getBusByNo(no)));
	}

	@ResponseBody
	@RequestMapping(value = "/rent/queryCtid", method = RequestMethod.GET, produces = {
			"application/json;charset=utf-8" })
	public String methodRent5(String ctid) throws Exception {
		String text = JSONObject.toJSONString(custService.queryScoreByCtid(ctid));
		System.out.println(text);
		return text;
	}
}
